package com.douqu.game.core.entity.sprite;

import com.douqu.game.core.entity.Skill;
import com.douqu.game.core.factory.ConstantFactory;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.util.LoadUtils;

/**
 * Created by bean on 2017/7/14.
 */
public class Soldier extends Sprite {

    public String enterEffect;

    /**
     * 类型
     * 1。地面
     * 2。飞行
     */
    public int unitType;

    /**
     * 种族
     * 1.联盟
     * 2.部落
     * 3.天灾
     * 4.中立
     */
    public int race;

    /** 攻击类型
     * 1.物理
     * 2.穿刺
     * 3.魔法
     * 4.英雄
     * */
    public int atkType;


    /** 释放范围(召唤出来的时候最远能放到几格) */
    public int initRange;

    /** 物理攻击 */
    public int physicsAtk;

    /** 穿刺攻击 */
    public int punctureAtk;

    /** 魔法攻击 */
    public int magicAtk;

    /** 攻击成长 */
    public int atkGrow;

    /** 防御类型
     * 1.物理
     * 2.穿刺
     * 3.魔法
     * 4.英雄
     * */
    public int defType;

    /** 物理防御 */
    public int physicsDef;

    /** 穿刺防御 */
    public int punctureDef;

    /** 魔法防御 */
    public int magicDef;

    /** 防御成长 */
    public int defGrow;

    /** 生命值 */
    public int hp;

    /** 生命成长 */
    public int hpGrow;

    /** 普通攻击技能 */
    public Skill defaultSkill;

    /** CD技能 */
    public Skill[] cdSkills;

    /** AI */
    public int ai;

    /** 视野(在视野范围内就要被吸引过去攻击) */
    public int vision;

    /** 所占格子区域 2表示2x2 1表示1x1 */
    public int gridArea;

    /**
     * 克制关系(对应SoldierRestrict类的ID)
     */
    public SoldierRestrict[] restrictType;


    /**
     * 是否能克制对方
     * @param target
     * @return
     */
    public boolean isRestrict(Soldier target)
    {
        for(SoldierRestrict type : restrictType)
        {
            if(type.isRestrict(target.restrictType))
                return true;
        }
        return false;
    }





    @Override
    public void setVariable(String key, String value)
    {
        if("cdSkills".equals(key))
        {
            String[] ids = value.split(ConstantFactory.SEMICOLON);
            cdSkills = new Skill[ids.length];
            for(int i = 0; i < ids.length; i++)
            {
                cdSkills[i] = DataFactory.getInstance().getGameObject(DataFactory.SKILL_KEY, Integer.parseInt(ids[i]));
                if(cdSkills[i] == null)
                {
                    System.out.println("Load Soldier cdSkills is Null:" + ids[i]);
                }
            }
        }
        else if("defaultSkill".equals(key))
        {
            this.defaultSkill = DataFactory.getInstance().getGameObject(DataFactory.SKILL_KEY, Integer.parseInt(value));
            if(defaultSkill == null)
            {
                System.out.println("Load Soldier defaultSkill is Null:" + value);
            }
        }
        else if("restrictType".equals(key))
        {
            String[] strs = value.split(ConstantFactory.SEMICOLON);
            restrictType = new SoldierRestrict[strs.length];
            SoldierRestrict obj = null;
            for(int i = 0; i < strs.length; i++)
            {
                obj = DataFactory.getInstance().getGameObject(DataFactory.SOLDIER_RESTRICT_KEY, Integer.parseInt(strs[i]));
                if(obj == null)
                {
                    System.out.println("Load Soldier restrictType error:" + strs[i]);
                }
                else
                {
                    restrictType[i] = obj;
                }
            }
        }
        else
            super.setVariable(key, value);
    }


}
